package study.java.jdk.jdk8._1_stream.collectors.summary;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import study.java.jdk.jdk8.DataUtils;
import study.java.jdk.jdk8.User;

import java.util.DoubleSummaryStatistics;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.LongSummaryStatistics;
import java.util.stream.Collectors;

@Slf4j
public class summarizing_Test {

    private List<User> userLt = DataUtils.buildUserLt();

    /**
     * @param mapper
     */
    @Test
    public void test1() {
        IntSummaryStatistics stats = userLt.stream()
                .collect(Collectors.summarizingInt(User::getAge));
        log.info("count= {}", stats.getCount());
        log.info("min= {}", stats.getMin());
        log.info("max= {}", stats.getMax());
        log.info("sum= {}", stats.getSum());
        log.info("avg= {}", stats.getAverage());
    }

    @Test
    public void test2() {
        LongSummaryStatistics stats = userLt.stream()
                .collect(Collectors.summarizingLong(User::getAge));
        log.info("count= {}", stats.getCount());
        log.info("min= {}", stats.getMin());
        log.info("max= {}", stats.getMax());
        log.info("sum= {}", stats.getSum());
        log.info("avg= {}", stats.getAverage());
    }


    @Test
    public void test3() {
        DoubleSummaryStatistics stats = userLt.stream()
                .collect(Collectors.summarizingDouble(User::getAge));
        log.info("count= {}", stats.getCount());
        log.info("min= {}", stats.getMin());
        log.info("max= {}", stats.getMax());
        log.info("sum= {}", stats.getSum());
        log.info("avg= {}", stats.getAverage());
    }
}
